package net.lzzy.algorithm.find;

public class BinarySearch<T extends Comparable<? super T>>extends BaseSearch<T> {
     BinarySearch(T[] itmes) {
        super(itmes);
    }
    @Override
    public int search(T key) {
         int start=0;
         int end=itmes.length-1;
         while (start<=end){
             int middle=(start+end)/2;
             int comp=compare(key,itmes[middle]);
             if (comp==0){
                 setTime( System.currentTimeMillis()-start);
                 return  middle;
             }else if (comp>0){
                 start=middle+1;
             }else{
                 end=middle-1;
             }
         }
        setTime( System.currentTimeMillis()-start);
        return -1;
    }
}
